package com.pageselect.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pageselect.dto.HjyCommunityDto;
import com.pageselect.entity.HjyCommunity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface HjyCommunityMapper extends BaseMapper<HjyCommunity> {
    @Select("<script>" +
                "SELECT \n" +
                "        hc.*, \n" +
                "        s1.name as \"province_name\",\n" +
                "        s2.name as \"city_name\",\n" +
                "        s3.name as \"town_name\"\n" +
                "    FROM \n" +
                "        hjy_community hc\n" +
                "    LEFT JOIN \n" +
                "        sys_area s1 ON hc.community_province_code = s1.code\n" +
                "    LEFT JOIN \n" +
                "        sys_area s2 ON hc.community_city_code = s2.code\n" +
                "    LEFT JOIN \n" +
                "        sys_area s3 ON hc.community_town_code = s3.code\n" +
                "    <where>\n" +
                "        <if test=\"communityName != null and communityName != ''\">\n" +
                "            hc.community_name LIKE CONCAT('%', #{communityName}, '%')\n" +
                "        </if>\n" +
                "        <if test=\"communityCode != null and communityCode != ''\">\n" +
                "            AND hc.community_code = #{communityCode}\n" +
                "        </if>\n" +
                "    </where>" +
            "</script>")
    List<HjyCommunityDto> queryList(HjyCommunity hjyCommunity);
}
